import { sphRequest } from "@/request";
import type { Numberable } from "@/store/slice/category";

export interface bannerType {
    id?: number;
    tmName: string;
    logoUrl: string;
}

// 获取产品列表
export const getProductList = (page: number, limit: number) => {
    return sphRequest({
        url: `/admin/product/baseTrademark/${page}/${limit}`,
        method: "GET",
    });
};

// 添加品牌
export const addProduct = (banner: bannerType) => {
    return sphRequest({
        url: "/admin/product/baseTrademark/save",
        method: "POST",
        data: banner,
    });
};

// 修改品牌
export const updateProduct = (banner: bannerType) => {
    return sphRequest({
        url: "/admin/product/baseTrademark/update",
        method: "PUT",
        data: banner,
    });
};

// 删除品牌
export const deleteProduct = (id: number) => {
    return sphRequest({
        url: `/admin/product/baseTrademark/remove/${id}`,
        method: "DELETE",
    });
};

// 获取一级分类
export const getFirstCategory = () => {
    return sphRequest({
        url: "/admin/product/getCategory1",
        method: "GET",
    });
};
// 获取二级分类
export const getSecondCategory = (category1Id: Numberable) => {
    return sphRequest({
        url: `/admin/product/getCategory2/${category1Id}`,
        method: "GET",
    });
};
// 获取三级分类
export const getThirdCategory = (category2Id: Numberable) => {
    return sphRequest({
        url: `/admin/product/getCategory3/${category2Id}`,
        method: "GET",
    });
};

// 商品属性列表
export const getAttrList = (category1Id: Numberable, category2Id: Numberable, category3Id: Numberable) => {
    return sphRequest({
        url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`,
        method: "GET",
    });
};

// 获取商品属性值
export const getAttrValueList = (attrId: number) => {
    return sphRequest({
        url: `/admin/product/getAttrValueList/${attrId}`,
        method: "GET",
    });
};

// 添加或更新商品属性
export const addOrUpdateAttr = (attr: any) => {
    return sphRequest({
        url: "/admin/product/saveAttrInfo",
        method: "POST",
        data: attr,
    });
};
// 删除商品属性
export const deleteAttr = (attrId: number) => {
    return sphRequest({
        url: `/admin/product/deleteAttr/${attrId}`,
        method: "DELETE",
    });
};
